home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Snippets / SplatMaster / WindowStuff < prev   
Encoding:
Text File  |  1992-03-08  |  6.0 KB  |  145 lines  |  [TEXT/PJMM]

  1.  a graphic growbox in the lower right corner}
  2.     procedure FakeGrowIcon; {(WPtr : WindowPtr; visible : boolean)}
  3.         var
  4.             bot, rght: integer;
  5.             R: rect;
  6.             pState: PenState;
  7.     begin
  8.         bot := WPtr^.portRect.bottom;
  9.         rght := WPtr^.PortRect.right;
  10.         SetRect(growIconRect, rght - 15, bot - 15, rght + 1, bot + 1);
  11.         if visible then
  12.             begin
  13.                 GetPenState(pState);
  14.                 EraseRect(growIconRect);
  15.                 FrameRect(growIconRect);
  16.                 SetRect(R, rght - 10, bot - 10, rght - 1, bot - 1);
  17.                 FrameRect(R);
  18.                 SetRect(R, rght - 12, bot - 12, rght - 5, bot - 5);
  19.                 EraseRect(R);
  20.                 FrameRect(R);
  21.                 SetPenState(pState);
  22.             end;{if visible}
  23.     end;
  24.  
  25. {===========================================================================}
  26.     procedure SetUpPalette;
  27.         const
  28.             numColors = 256;    {256 - 2; 2 spots reserved for black & white}
  29.             colorsAvail = 254;
  30.         var
  31.             i: integer;
  32.             num: real;
  33.             anRGB: RGBColor;
  34.     begin
  35.         mainWindPalette := NewPalette(256, nil, pmCourteous, $5000);
  36. {mainWindPalette := GetPalette(mainWindowPtr);}
  37.  
  38.         anRGB.red := 2 * maxInt;
  39.         anRGB.blue := 2 * maxInt;
  40.         anRGB.green := 2 * maxInt;
  41.         SetEntryColor(mainWindPalette, 0, anRGB);    {first Entry is white}
  42.         anRGB.red := 0;
  43.         anRGB.blue := 0;
  44.         anRGB.green := 0;
  45.         SetEntryColor(mainWindPalette, 255, anRGB);    {last entry is black}
  46.  
  47.         for i := 1 to numColors - 1 do            {defaults to grays}
  48.             begin
  49.                 num := 1 - i / (colorsAvail);
  50.                 anRGB.red := 2 * (round(num * maxint));
  51.                 anRGB.blue := 2 * (round(num * maxint));
  52.                 anRGB.green := 2 * (round(num * maxint));
  53.                 SetEntryColor(mainWindPalette, i + 1, anRGB);
  54.             end;
  55.  
  56.         for i := 1 to numColors do
  57.             ProtectEntry(i, TRUE);
  58.     end;
  59.  
  60. {===========================================================================}
  61.     procedure PutUpDrawingWIND;
  62.         var
  63.             Screen: Rect;
  64.             offSet: point;
  65.     begin
  66.         if hasColorQD then
  67.             begin
  68.                 DrawWindPtr := GetNewCWindow(1000, @mainWindowStorage, pointer(-1));
  69.                 SetUpPalette;
  70.                 SetPalette(DrawWindPtr, mainWindPalette, TRUE);
  71.                 ActivatePalette(DrawWindPtr);
  72.             end
  73.         else
  74.             DrawWindPtr := GetNewWindow(1000, @mainWindowStorage, WindowPtr(-1));
  75.  
  76.         SetPort(DrawWindPtr);
  77.  
  78.         offSet.h := (ScreenBits.bounds.right - DrawWindPtr^.portRect.right) div 2;
  79.         offSet.v := 37 + (ScreenBits.bounds.bottom - DrawWindPtr^.portRect.bottom) div 3;
  80. {not calculating currMenuHeight yet}
  81. {    offSet.v := currMenuHeight + (ScreenBits.bounds.bottom - DrawWindPtr^.portRect.bottom) div 3;}
  82.         MoveWindow(DrawWindPtr, offSet.h, offSet.v, TRUE);
  83.  
  84.         clippingRect := DrawWindPtr^.portRect;
  85.         InsetRect(clippingRect, 1, 1);
  86.         ClipRect(clippingRect);
  87.  
  88.         SetWTitle(DrawWindPtr, 'SplatMaster');
  89.         ShowWindow(DrawWindPtr);
  90.         FakeGrowIcon(DrawWindPtr, prefs.def_alwaysGrowBox);
  91.     end;
  92.  
  93.  
  94. {===========================================================================}
  95.     procedure CloseDrawingWIND;
  96.     begin
  97.         CloseWindow(DrawWindPtr);
  98.     end;
  99.  
  100.  
  101. {===========================================================================}
  102.     procedure CenterWindow (theWindow: WindowPtr);
  103.  
  104.         const
  105.             MBarHeight = $BAA;
  106.         type
  107.             WordPtr = ^INTEGER;
  108.         var
  109.             theX, theY: INTEGER;
  110.             scrnNoMB: Rect;        (* Rectangle of the screen without Menu Bar. *)
  111.     begin
  112.         with WindowPeek(theWindow)^.port do
  113.             begin
  114.                 with screenBits do
  115.                     begin
  116.                         theX := ((bounds.right - bounds.left) - (portRect.right - portRect.left)) div 2;
  117.                         theY := ((bounds.bottom - bounds.top) - (portRect.bottom - portRect.top)) div 3;
  118.                     end
  119.             end;
  120.         theY := theY + WordPtr(MBarHeight)^;
  121.         MoveWindow(theWindow, theX, theY, FALSE);
  122.     end;
  123.  
  124.  
  125. {===========================================================================}
  126.     procedure DoDrag;{(theWindow : WindowPtr);}
  127.     begin
  128. {this allows the user to drag a window around in the rectangle defined by}
  129. {ScreenBits.bounds.}
  130.         DragWindow(theWindow, MainEvent.where, ScreenBits.bounds);
  131.     end;
  132.  
  133. {===========================================================================}
  134.     procedure DoGrow;{(theWindow : WindowPtr);}
  135.         var
  136.             Wptr, oldPort: Windowptr;
  137.             sizeRect: rect;
  138.             newSize: longint;
  139.             newWidth, newHeight: integer;
  140.             r: rect;
  141.             bot, rght: integer;
  142.  
  143.     begin
  144.         GetPort(oldPort);
  145.         Se